title: “assignment 8” output: html_document output_file: “C:\Users\student\OneDrive - Bryant University\Documents\GitHub\Math421\assignment8.html” knit: (function(inputFile, encoding) { options(repos = c(CRAN = “https://cran.rstudio.com/”)) rmarkdown::render(inputFile, encoding = encoding) }) —
How to do it?:
Open the Rmarkdown file of this assignment (link) in Rstudio.
Right under each question, insert a code chunk
(you can use the hotkey Ctrl + Alt + I to add a code chunk)
and code the solution for the question.
Knit the rmarkdown file (hotkey:
Ctrl + Alt + K) to export an html.
Publish the html file to your Githiub Page.
Submission: Submit the link on Github of the assignment to Canvas
gganimate and gifski
then restart Rstudio. Using the Adult Census Income data,
make an animation using geom_point and
transition_states.getwd()
## [1] "C:/Users/student/Downloads"
library(tidyverse)
library(gganimate)
library(gifski)
library(ggplot2)
library(knitr)
df = read_csv("adult_census_missing.csv")
plot1 = ggplot(df,
aes(x = education.num,
y = hours.per.week))+
geom_point(size=4) +
transition_states(income)+
labs(title = 'income: {closest_state}')
animate(plot1, nframes = 400)
Adult Census Income data, make an animation
using geom_bar and transition_states.library(tidyverse)
library(gganimate)
library(gifski)
library(knitr)
library(dplyr)
df = read_csv("adult_census_missing.csv")
df_clean <- df %>% filter(!is.na(sex))
plot2 <- df_clean %>%
ggplot(aes(x = sex, fill = income)) +
geom_bar(position = "fill") +
transition_states(education.num) +
labs(title = "education.num: {closest_state}")
animate(plot2, nframes = 400)
setwd("C:\\Users\\student\\OneDrive - Bryant University\\Documents\\GitHub\\Math421")
df2 <- read_csv("WHO-COVID-19-global-data.csv")
library(lubridate)
df2$Date_reported <- as.Date(df2$Date_reported)
df2$months <- month(df2$Date_reported)
d1 <- df2 %>% group_by(months, Country) %>% summarise(mean = mean(Cumulative_deaths))
d2 <- d1 %>% group_by(months) %>% mutate(rank=rank(-mean))
d3 <- d2 %>% filter(rank <= 10)
plot3 <- d3 %>%
ggplot(aes(x=rank, y=mean, group=Country, fill=Country)) +
geom_col() +
geom_text(aes(label=Country), hjust=1.4) +
coord_flip(clip="off", expand=FALSE) +
scale_x_reverse() +
labs(title='Month: {closest_state}', x='', y='Cumulative Deaths') +
theme(plot.title = element_text(hjust=1, size=22),
axis.text.y=element_blank(),
axis.ticks.y=element_blank()) +
transition_states(months)
animate(plot3, nframes = 400)

setwd("C:\\Users\\student\\OneDrive - Bryant University\\Documents\\GitHub\\Math421")
df3 = read.csv('all-states-history.csv')
df3 <- df3 %>% filter(deathIncrease>0, positiveIncrease>0)
df3$date = as.Date(df3$date, format = "%m/%d/%Y")
df3$year <- year(df3$date)
d1 <- df3 %>% group_by(year, state) %>% summarise(mean = mean(positive))
d2 <- d1 %>% group_by(year) %>% mutate(rank=rank(-mean))
d3 <- d2 %>% filter(rank <= 10)
plot4 <- d3 %>% ggplot(aes(x=rank, y=mean, group=state, fill=state, label=state)) + geom_col()+
geom_text(aes(y = mean, label = state), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(
title = 'Year: {closest_state}', x = '',
y = 'Total Number of Positive Cases',
fill = 'state'
) +
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) + transition_states(year)+
ease_aes("cubic-in-out")
animate(plot4, nframes = 400)
